/*******************************************************************************
																				
	DESCRIPTION:  	This do file creates functions that help automate the process
					of calculating the main statistics of interest for the predictions.
	
*******************************************************************************/

* Variable names:
program namer, rclass

	args months unempl
	
	return local outcome emplAft`months'M_`unempl'M_In
	return local pred p_emplAft`months'M_`unempl'M_In

end

* Main stats:
program stats, rclass

	syntax varlist(min = 2 max = 2) [if] [in]
	
	tokenize `varlist'
	
	qui {
		preserve 
		keep if !missing(`1', `2')
		
		* Regress empirical JFR on predicted JFR and store coefficients and R-squared
		reg `1' `2' `if' `in'
		return local r2 : display %9.3f `e(r2)'
		return local n : display %9.0fc `e(N)'
		return local r2_ex = `e(r2)'
		return local n_ex = `e(N)'
		
		* Get covariance:
		corr `1' `2' `if' `in', covariance
		return local cov : display %9.3f `r(cov_12)'
		return local cov_ex = `r(cov_12)'
		
		* Get means and variances:
		sum `1' `if' `in'
		return local mean_f : display %9.3f `r(mean)'
		return local var_f : display %9.3f `=r(sd)^2'
		return local mean_f_ex = `r(mean)'
		return local var_f_ex = `=r(sd)^2'
		
		sum `2' `if' `in'
		return local mean_f_hat : display %9.3f `r(mean)'
		return local var_f_hat : display %9.3f `=r(sd)^2'
		return local mean_f_hat_ex = `r(mean)'
		return local var_f_hat_ex = `=r(sd)^2'
	}

end

